
#include "fs.h"

struct statfs datafs;
struct statfs systemfs;
struct statfs sdcardfs;
struct statfs cachefs;

void fs_dump();

void init_filesystem()
{
    fs_dump();
}

void filesystem_cleanup(void)
{}

void fs_dump()
{
    memset(&datafs, 0, sizeof(statfs));
    memset(&systemfs, 0, sizeof(statfs));
    memset(&sdcardfs, 0, sizeof(statfs));
    memset(&cachefs, 0, sizeof(statfs));

    statfs(DATA_PATH, &datafs);
    statfs(SYSTEM_PATH, &systemfs);
    statfs(SDCARD_PATH, &sdcardfs);
    statfs(CACHE_PATH, &cachefs);
}

long long get_fs_system_total()
{
    return ((long long)systemfs.f_blocks * (long long)systemfs.f_bsize) / 1024;
}

long long get_fs_data_total()
{
    return ((long long)datafs.f_blocks * (long long)datafs.f_bsize) / 1024;
}

long long get_fs_sdcard_total()
{
    return ((long long)sdcardfs.f_blocks * (long long)sdcardfs.f_bsize) / 1024;
}

long long get_fs_cache_total()
{
    return ((long long)cachefs.f_blocks * (long long)cachefs.f_bsize) / 1024;
}

long long get_fs_system_used()
{
    return ((long long)(systemfs.f_blocks - (long long)systemfs.f_bfree) * systemfs.f_bsize) / 1024;
}

long long get_fs_data_used()
{
    return ((long long)(datafs.f_blocks - (long long)datafs.f_bfree) * datafs.f_bsize) / 1024;
}

long long get_fs_sdcard_used()
{
    return ((long long)(sdcardfs.f_blocks - (long long)sdcardfs.f_bfree) * sdcardfs.f_bsize) / 1024;
}

long long get_fs_cache_used()
{
    return ((long long)(cachefs.f_blocks - (long long)cachefs.f_bfree) * cachefs.f_bsize) / 1024;
}

long long get_fs_system_ava()
{
    return ((long long)systemfs.f_bfree * (long long)systemfs.f_bsize) / 1024;
}

long long get_fs_data_ava()
{
    return ((long long)datafs.f_bfree * (long long)datafs.f_bsize) / 1024;
}

long long get_fs_sdcard_ava()
{
    return ((long long)sdcardfs.f_bfree * (long long)sdcardfs.f_bsize) / 1024;
}

long long get_fs_cache_ava()
{
    return ((long long)cachefs.f_bfree * (long long)cachefs.f_bsize) / 1024;
}
